﻿using Echart.Model.Option;
using Newtonsoft.Json;
using System.Web;

namespace Echart.BLL.Echarts
{
    public class OptionManager
    {
        internal string TypeTransfer(option opt)
        {
            var value = JsonConvert.SerializeObject(opt);
            return NewtonsoftJson(opt);
        }

        public static string NewtonsoftJson(object obj)
        {
            var jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };

            return JsonConvert.SerializeObject(obj, Formatting.Indented, jsonSetting);
        }

        private static void WriteJson(string str)
        {
            HttpContext.Current.Response.Write(str);
            //HttpContext.Current.Response.ContentType = "text/plain"; //设置MIME格式
            HttpContext.Current.Response.End();
        }

        /// <summary>
        /// 获取示例option并Json序列化
        /// </summary>
        /// <param name="optName"></param>
        /// <returns></returns>
        public string GetOption(string optName)
        {
           var option = EchartManager.Current.SampleManager.CreateSample(optName);
           return TypeTransfer(option);
        }
    }
}
